package mhwi.powers;

import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.actions.utility.UseCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import mhwi.helper.ModHelper;
import mhwi.relics.CangLanXingRelic;
import mhwi.relics.TaiDaoRelic;

public class ZhanWeiPower extends TemplatePower {
    private static final Class<? extends TemplatePower> CLASS = ZhanWeiPower.class;
    private static final String CLASS_NAME = CLASS.getSimpleName();
    public static final String POWER_ID = ModHelper.makeId(CLASS_NAME);
    private static final int maxCountLimit = 6;
    private static int currentCountLimit = 3;

    public ZhanWeiPower(AbstractCreature owner, int amount) {
        super(owner, amount, CLASS);
    }

    public ZhanWeiPower(AbstractCreature owner) {
        this(owner, currentCountLimit);
    }

    @Override
    public void updateDescription() {
        this.description = super.DESCRIPTIONS[0];
    }

    @Override
    public void onUseCard(AbstractCard card, UseCardAction action) {
        super.onUseCard(card, action);
        if (card.type == AbstractCard.CardType.ATTACK && ModHelper.hasRelic(CangLanXingRelic.ID) && ModHelper.hasRelic(TaiDaoRelic.ID)) {
            AbstractDungeon.actionManager.addToTop(new ReducePowerAction(this.owner, this.owner, this.ID, 1));
            this.updateDescription();
        }
    }

    @Override
    public void stackPower(int stackAmount) {
        if (this.amount + stackAmount > currentCountLimit) {
            stackAmount = currentCountLimit - this.amount;
        }

        super.stackPower(stackAmount);
        this.updateDescription();
    }


    @Override
    public void atEndOfRound() {
    }

    public static void increaseCurrentCountLimit() {
        increaseCurrentCountLimit(1);
    }

    public static void increaseCurrentCountLimit(int amount) {
        currentCountLimit += amount;
        if (currentCountLimit > maxCountLimit) {
            currentCountLimit = maxCountLimit;
        }
    }

    public static int getCurrentCountLimit() {
        return currentCountLimit;
    }
}
